package com.jobchecks.sms.config;

import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * Knife4j & Swagger2配置
 *
 * @author huangjinjia
 */
@Configuration
// 启用Swagger
@EnableSwagger2
@EnableKnife4j
public class Swagger2Config {

    @Value("${jobchecks.name}")
    private String projectName;

    @Value("${server.port}")
    private String serverPort;

    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .useDefaultResponseMessages(false)
                // 接口基本信息
                .apiInfo(apiInfo())
                // 分组名称
                .groupName(projectName)
                .select()
                // 扫描接口所在包路径
                .apis(RequestHandlerSelectors.basePackage("com.jobchecks.sms"))
                // 路径使用any风格(指定所有路径)
                .paths(PathSelectors.any())
                .build();

    }

    /**
     * 设置文档信息主页的内容说明
     *
     * @author huangjinjia
     */
    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("短信服务模块" )
                .description("供技术人员查看、调试接口使用")
                // 文档默认访问地址：http://IP:端口/services/doc.html
                .termsOfServiceUrl("http://localhost:".concat(serverPort).concat("/service/"))
                .contact(new Contact("Huangjinjia",null,"81476724@qq.com"))
                .version("1.0.0-SNAPSHOT")
                .build();
    }

}
